package top.minuy.util.helper;

import top.minuy.algorithm.search.string.SubstringMatch;
import top.minuy.util.constant.SubstringMatchType;

/**
 * @author Minuy
 * @time 16:29
 * @date 2021/11/12
 */
public class SubstringMatchHelper {

    public static void matchTest(SubstringMatchType type, String s, String t) {
        long startTime = System.nanoTime();
        int pos = -1;
        if (type == SubstringMatchType.bruteForce) {
            pos = SubstringMatch.bruteForce(s, t);
        }else  if (type == SubstringMatchType.rabinKarp) {
            pos = SubstringMatch.rabinKarp(s, t);
        }else if (type == SubstringMatchType.kmp){
            pos = SubstringMatch.KMP(s,t);
        }
        long endTime = System.nanoTime();

        boolean isOk = true;
        if (s.indexOf(t) != pos) {
            isOk = false;
        }
        System.out.println(String.format("%s : ok = %s, s.length = %d, t.length = %d, pos = %d, time = %f s",
                type.toString(),isOk, s.length(), t.length(), pos, (endTime - startTime) / 1000000000.0));
    }
}
